package com.example.juc.demo;

import java.util.Random;

public class ThreadLocalDemo {

    static ThreadLocal tl=new ThreadLocal<Integer>();

    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {

            new Thread(()->{
                int value = getValue();
                tl.set(value);
                System.out.println(Thread.currentThread().getName()+" before remove:"+tl.get());
                tl.remove();
                System.out.println(Thread.currentThread().getName()+" after remove:"+tl.get());

            },String.valueOf(i)).start();
        }
    }

    public static int getValue() {
        return new Random().nextInt(5);
    }
}
